package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-02-24 14:03
 * @Description: the class uac redis controller
 */
@RestController
@RequestMapping(value = "/redis", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacRedisController {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     *
     *
     * @param key
     * @param value
     * @return
     */
    @RequestMapping("/redisSet")
    public Wrapper redisSet(String key, String value) {

        redisTemplate.opsForValue().set(key, value);

        //return WrapMapper.ok();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null));
    }

    @RequestMapping("/redisGet")
    public Wrapper redisGet(String key) {

        String value = redisTemplate.opsForValue().get(key) + "";

        //return WrapMapper.ok(value);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null));
    }

}
